import { createRouter, createWebHistory,createWebHashHistory } from "vue-router";
import NProgress from "@/utils/progress";
import { PROD_TITLE } from "../config";

const routes = [
  {
    path: "/",
    name: "layout",
    component: () => import("@/layout/index.vue"),
    //重定向
    redirect: "/security-board",
    children: [
      {
        path: "/security-board",
        name: "SecurityBoard",
        component: () => import("@/views/security-board/index.vue"),
      },
      {
        path: "/operation-board",
        name: "OperationBoard",
        component: () => import("@/views/operation-board/index.vue"),
      },
      {
        path: "/car-board",
        name: "CarBoard",
        component: () => import("@/views/car-board/index.vue"),
      },
      {
        path: "/people-board",
        name: "PeopleBoard",
        component: () => import("@/views/people-board/index.vue"),
      },
    ],
  },
];

const router = createRouter({
  history:createWebHashHistory(),
  routes,
});

/**
 * 前置守卫
 */
router.beforeEach(async (to, from, next) => {
  // if (to.name === "DataPanel") {
  //   next({ name: "BuildPrj" });
  // }
  // console.log("to", to);
  NProgress.start();
  next();
});
/**
 * 后置守卫
 */
router.afterEach((to) => {
  NProgress.done();
  const title = to.meta?.title;
  document.title = PROD_TITLE + `${title ? "-" + title : ""}`;
});

export default router;
